package com.ruoyi.college.service.impl;

import java.util.List;

import com.ruoyi.college.domain.*;
import com.ruoyi.college.domain.Class;
import com.ruoyi.college.service.*;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.college.mapper.ExperimentClassProjectMapper;
import com.ruoyi.common.core.text.Convert;

/**
 * 班级实验内容安排Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-30
 */
@Service
public class ExperimentClassProjectServiceImpl implements IExperimentClassProjectService 
{
    @Autowired
    private ExperimentClassProjectMapper experimentClassProjectMapper;

    @Autowired
    private ICourseService courseService;

    /**
     * 查询班级实验内容安排
     * 
     * @param classProjectId 班级实验内容安排主键
     * @return 班级实验内容安排
     */
    @Override
    public ExperimentClassProject selectExperimentClassProjectByClassProjectId(Long classProjectId)
    {
        return experimentClassProjectMapper.selectExperimentClassProjectByClassProjectId(classProjectId);
    }

    @Autowired
    private ICourseArrangementService courseArrangementService;

    @Autowired
    private IClassService classService;

    @Autowired
    private IExperimentProjectService experimentProjectService;

    /**
     * 查询班级实验内容安排列表
     * 
     * @param experimentClassProject 班级实验内容安排
     * @return 班级实验内容安排
     */
    @Override
    public List<ExperimentClassProject> selectExperimentClassProjectList(ExperimentClassProject experimentClassProject)
    {
        List<ExperimentClassProject> experimentClassProjects = experimentClassProjectMapper.selectExperimentClassProjectList(experimentClassProject);
        experimentClassProjects.forEach(e->{
            Long arrangementId = e.getArrangementId();
            CourseArrangement courseArrangement = courseArrangementService.selectCourseArrangementByArrangementId(arrangementId);
            Long courseId = courseArrangement.getCourseId();
            Course course = courseService.selectCourseByCourseId(courseId);
            e.setCourseId(courseId);
            e.setCourseName(course.getCourseName());
            //
            Class aClass = classService.selectClassByClassId(e.getClassId());
            e.setClassName(aClass.getClassName());
            ExperimentProject experimentProject = experimentProjectService.getProjectByProjectId(e.getProjectId());
            e.setProjectName(experimentProject.getProjectName());
        });
        return experimentClassProjects;
    }

    /**
     * 新增班级实验内容安排
     * 
     * @param experimentClassProject 班级实验内容安排
     * @return 结果
     */
    @Override
    public int insertExperimentClassProject(ExperimentClassProject experimentClassProject)
    {
        experimentClassProject.setCreateTime(DateUtils.getNowDate());
        return experimentClassProjectMapper.insertExperimentClassProject(experimentClassProject);
    }

    /**
     * 修改班级实验内容安排
     * 
     * @param experimentClassProject 班级实验内容安排
     * @return 结果
     */
    @Override
    public int updateExperimentClassProject(ExperimentClassProject experimentClassProject)
    {
        experimentClassProject.setUpdateTime(DateUtils.getNowDate());
        return experimentClassProjectMapper.updateExperimentClassProject(experimentClassProject);
    }

    /**
     * 批量删除班级实验内容安排
     * 
     * @param classProjectIds 需要删除的班级实验内容安排主键
     * @return 结果
     */
    @Override
    public int deleteExperimentClassProjectByClassProjectIds(String classProjectIds)
    {
        return experimentClassProjectMapper.deleteExperimentClassProjectByClassProjectIds(Convert.toStrArray(classProjectIds));
    }

    /**
     * 删除班级实验内容安排信息
     * 
     * @param classProjectId 班级实验内容安排主键
     * @return 结果
     */
    @Override
    public int deleteExperimentClassProjectByClassProjectId(Long classProjectId)
    {
        return experimentClassProjectMapper.deleteExperimentClassProjectByClassProjectId(classProjectId);
    }
}
